#!/bin/bash

USAGE="`basename $0` [-w|--warning]"

if [ $# -ne 2 ];then
    echo -e "\nWrong Syntax:`basename $0` $*"
    echo -e "\nUsage: $USAGE\n"
    exit 2
fi

case "$1" in
    -w|--warning)
        shift
        WAR=$1
        ;;
    *)
        echo -e "\nWrong Syntax:`basename $0` $*"
        echo -e "\nUsage: $USAGE\n"
        exit 2
esac
if [ -x /usr/sbin/lsof ];then
    counts=$(/usr/sbin/lsof -n|wc -l)
    echo "Total open files $counts |openfiles:$counts:$WAR"
else
    echo "Can't find command lsof" 
    exit 1
fi

if [ $counts -lt $WAR ];then
    exit 0
else
    exit 1
fi
